package com.cipta.lomob.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.cipta.lomob.R;
import com.cipta.lomob.adapter.ItemCategoryAdapter;
import com.cipta.lomob.base.BaseFragment;

public class ItemCategoryFragment extends BaseFragment{
	private ListView lvLive, lvRecent;
	private ProgressBar indicator;
	private Button btnLive, btnRecent;
	
	public static String FRAGMENT_TAG = "ItemCategoryFragment";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initializeLibs();
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_item_by_category, container, false);
		initializeViews(view);
		return view;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		initializeProcess();
		initializeActions();
	}
	
	@Override
	public void initializeViews(View view) {
		// TODO Auto-generated method stub
		super.initializeViews(view);
		setHasOptionsMenu(true);
		
		getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
		getActivity().getActionBar().setTitle("MUSIC");
		
		lvLive = (ListView)view.findViewById(R.id.lv_item_category_live);
		lvRecent = (ListView)view.findViewById(R.id.lv_item_category_recent);
		indicator = (ProgressBar)view.findViewById(R.id.pb_indicator);
		btnLive = (Button)view.findViewById(R.id.btn_item_by_category_live);
		btnRecent = (Button)view.findViewById(R.id.btn_item_by_category_recent);
	}
	
	@Override
	public void initializeLibs() {
		super.initializeLibs();
	}
	
	@Override
	public void initializeProcess() {
		super.initializeProcess();
		btnLive.setBackgroundResource(R.drawable.tab_on_category);
		btnRecent.setBackgroundResource(R.drawable.tab_off_category);
		
		lvLive.setAdapter(new ItemCategoryAdapter(getActivity()));
		lvRecent.setAdapter(new ItemCategoryAdapter(getActivity()));
		
		indicator.setVisibility(View.GONE);
		
		lvLive.setVisibility(View.VISIBLE);
		lvRecent.setVisibility(View.GONE);
	}
	
	@Override
	public void initializeActions() {
		super.initializeActions();
		
		btnLive.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				btnLive.setBackgroundResource(R.drawable.tab_on_category);
				btnRecent.setBackgroundResource(R.drawable.tab_off_category);
				
				lvLive.setVisibility(View.VISIBLE);
				lvRecent.setVisibility(View.GONE);
			}
		});
		
		btnRecent.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				btnLive.setBackgroundResource(R.drawable.tab_off_category);
				btnRecent.setBackgroundResource(R.drawable.tab_on_category);
				
				lvLive.setVisibility(View.GONE);
				lvRecent.setVisibility(View.VISIBLE);
			}
		});
	}
	
	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		super.onCreateOptionsMenu(menu, inflater);
		inflater.inflate(R.menu.menu_item_category, menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId()==R.id.action_broadcast) {
			Toast.makeText(getActivity(), "To Broadcast", Toast.LENGTH_LONG).show();
		}
		
		if (item.getItemId()==android.R.id.home) {
			Toast.makeText(getActivity(), "Back", Toast.LENGTH_LONG).show();
		}
		
		return super.onOptionsItemSelected(item);
	}
}
